package project.android;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class TaskListViewAdapter extends BaseAdapter{
	
	final Context context;
    static String[] tasks;
    static boolean[] overdatedFlag;
     

    public TaskListViewAdapter(Context context, String[] data, boolean[] overdate) {
        this.context = context;
        tasks = data;
        overdatedFlag = overdate;
    }

    public int getCount() {
        return tasks.length;
    }

    public Object getItem(int position) {
        return tasks[position];
    }

    public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup viewGroup) {
        
        
        if (convertView == null) {
            LayoutInflater inflater = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.task_row_view, null);
        }
        
        TextView taskname = (TextView) convertView.findViewById(R.id.taskname1);
        taskname.setText(tasks[position]);

        int j;
        for(j = 0; j < tasks.length;j++)
    		if(tasks[j] == getItem(position)) break;
        if(overdatedFlag[j] == true){
        	
        	ImageView iv = (ImageView) convertView.findViewById(R.id.image);
        	iv.setImageResource(R.drawable.icon_exclamation);
        	
        	
        }
        	
        return convertView;
    }

}
